<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.edatagrid.js"></script>
		<script type="text/javascript" src="../../../JS/addRowShareFunction.js"></script>
	</head>

	<body style="padding:0px;background-color: white">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div>
			<div style="float: right;margin-top: 0px;max-width:60px;" id="notreview"></div>
			<form id="ff" action="#" method="post">
				<table id="basicInfo" cellpadding="5" class="displaytable" style="text-align: left;width: 80%;margin: 0 auto;">
					<tr>
						<td width="10%">
							<h id="star">* </h>纠纷事件编号</td>
						<td width="20%">
							<input class="easyui-textbox" style="width:80%;" type="text" name="ORDER_NO" id="input_ORDER_NO" data-options="prompt:'由系统自动生成，不需填写',disabled:true" />
						</td>
						<td width="10%">
							<h id="star">* </h>发生时间</td>
						<td width="20%">
							<input class="easyui-datebox" style="width: 80%" type="text" name="TIME" id="input_TIME" data-options="required:true" />
						</td>
						<td width="10%">
							<h id="star">* </h>纠纷类型</td>
						<td width="20%">
							<input class="easyui-textbox" style="width:80%;" type="text" name="DISPUTE_TYPE" id="input_DISPUTE_TYPE" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td width="10%">
							<h id="star">* </h>值班领导</td>
						<td width="20%">
							<input class="easyui-textbox" style="width:80%;" type="text" name="PRINCIPAL" id="input_PRINCIPAL" />
						</td>
						<td width="10%">
							<h id="star">* </h>经办人</td>
						<td width="20%">
							<input class="easyui-textbox" style="width:80%;" type="text" name="OPERATOR" id="input_OPERATOR" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>纠纷情况</td>
						<td colspan="5">
							<input class="easyui-textbox" style="width:95%;" type="text" name="CONTEXT" id="input_CONTEXT" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>处理结果</td>
						<td colspan="5">
							<input class="easyui-textbox" style="width:95%;" type="text" name="PROCESSED" id="input_PROCESSED" data-options="required:true"></input>
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>处理方式及依据</td>
						<td colspan="5">
							<input class="easyui-textbox" style="width:95%;" type="text" name="PROCESSING" id="input_PROCESSING" data-options="required:true"></input>
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>原因分析</td>
						<td colspan="5">
							<input class="easyui-textbox" style="width:95%;" type="text" name="REASON" id="input_REASON" data-options="required:true" />
						</td>
					</tr>
				</table>
				<table>
					<tr style="display: none;">
						<td>
							<h id="star">* </h>ID</td>
						<td>
							<input class="easyui-textbox" style="width:80%;" type="text" name="ID" id="input_ID" />
						</td>
						<td>
							<h id="star">* </h>事件类型</td>
						<td>
							<input value="0" class="easyui-textbox" style="width:80%;" type="text" name="EVENT_TYPE" id="input_EVENT_TYPE" />
						</td>
					</tr>
				</table>
				<table id="tt" style="width: 100%;">

				</table>
				<div style="margin-left: 20%;" id="new_footer">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="no"></iframe>
		</div>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/MarketShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var currid = AddFlag; //当前页面的ID
		var id = getID(); //获取上个页面传回的ID
		var currPage = 0; //当前的页数
		var MaxPage = 0;
		var MinPage = 1;
		var updateData;
		var isVerify = 0;
		var currRow;
		var _detailToolbarData;
		_detailToolbarData = AddDetailToolBar(7);
		$(document).ready(function(){
			if(id != AddFlag && id != undefined) {
				currid = id;
				loadRemote();
			}
        });
		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL;
		receipts_type += RECEIPT_SEARCH_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_EXPORT_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content);
		GetDetailTable();
		addFooter($("#new_footer"));
		getPageMaxAndMin();

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/market/emergency/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function loadRemote() {
			var _url = RemoteLinkAddress + '/market/emergency/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result.msg === "prenull") {
						$.messager.alert("消息", "没有上张");
						return;
					}
					if(result.msg === "nextnull") {
						$.messager.alert("消息", "没有下张");
						return;
					}
					updateData = deepCopy(result);
					isVerify = result.ISVERIFY;
					verifyStatus(result.ISVERIFY, true);
					getFormData(result);
					currPage = result.ID;
					currid = result.ID;
					var _data = result.rows;
					$('#tt').edatagrid('loadData', _data);
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		//导出
		function exportExcel() {
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/market/emergency/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
							//							this.onClick(location = result.path);
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		//单据的相关功能
		function frontpage() { //上一张
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/market/emergency/pre.do?ID=' + currPage + '&EVENT_TYPE=' + 0;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() { //下一张
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/market/emergency/next.do?ID=' + currPage + '&EVENT_TYPE=' + 0;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}
		}

		function newdata() {
			$("#notreview").empty(); //去掉审核或者未审核的图片
			isVerify = 0; //将状态改为未审核
			currid = AddFlag;
			currPage = 0;
			$('#ff').form('reset');
			$('#tt').datagrid('loadData', {
				total: 0,
				rows: []
			});
		}

		function save() { //保存
			if(currid != AddFlag && isVerify == "1") {
				$.messager.alert('警告', '该单据已通过审核，不可修改！');
				return;
			}
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			var s=$('#tt').edatagrid('getRows');
			if(s.length==0){
				$.messager.alert("警告", "明细不能为空");
				return;
			}
			if(currid != AddFlag) {
				getUpdateData();
			} else {
				getSaveData();
			}
		}


		function getUpdateData() {
			var data = submitFormData();
			data.rows = updateData.rows;
			submitData(data);
		}

		function getSaveData() {
			var data = submitFormData();
			data.rows = $("#tt").datagrid("getRows");
			submitData(data);
		}

		function submitData(_data) {
			var _url = "";
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/market/emergency/save.do";
			} else {
				_url = RemoteLinkAddress + "/market/emergency/update.do";
			}
			var _senddata = JSON.stringify(_data);
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: 'a=' + _senddata,
				type: "POST",
				success: function(result) {
					var revData = result.msg.split(";");
					if(revData[0] != "success" || result == null) {
						$.messager.alert('提示信息', '保存失败!');
						return;
					}
					if(currid == AddFlag) {
						$("#input_ORDER_NO").textbox("setValue", revData[2]);
						$("#input_ID").textbox("setValue", revData[1]);
						currid = revData[1];
						currPage = revData[1];
						$(document).ready(function(){
							loadRemote();
						});
						$.messager.alert("提示", "新建保存成功");
						return;
					}
					$.messager.alert("提示", "修改保存成功");
				},
				error: function(result) {
					$.messager.alert("错误", "保存失败");
				}
			});
		}

		function deletedata() { //删除
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不能删除！");
				return;
			}
			if(isVerify == 1) {
				$.messager.alert('警示', "该单据已审核，不可以删除！");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/emergency/delete.do", {
							"ID": currid
						},
						function(result) {
							if(result.msg == "success") {
								$('#tt').datagrid('reload');
								$.messager.alert({
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function verifydata() { //审核
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可审核！");
				return;
			}
			var _url = RemoteLinkAddress + "/market/emergency/verify.do";
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: {
					ID: currid
				},
				type: "POST",
				success: function(result) {
					$.messager.alert("成功", "审核成功");
					isVerify = "1";
					verifyStatus(isVerify, true);
				},
				error: function(result) {
					$.messager.alert("失败", "审核失败");
				}
			});
		}

		function unverifydata() {
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可审核！");
				return;
			}
			if(isVerify == 0) {
				$.messager.alert("警告", "订单已经弃审");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/emergency/unverify.do", {
							"ID": currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '弃审成功!'
								});
								isVerify = 0;
								verifyStatus(isVerify, true);
							} else {
								$.messager.alert({
									title: '错误',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function searchmore() { //查询
			AddTabIn("纠纷事件查询", parent.$('#tabs'), "UI/Market/DisputeEventManagement/DisputeEventManagementSearch.html");
		}

		function print() { //打印
			var pLocation = "";

			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可打印！");
				return;
			}
			if(currid == AddFlag || isVerify != 1) {
				$.messager.alert('警示', "该单据未审核，不可以打印！");
				return;
			}
			pLocation = "DisputeEventManagementPrint.html?id=" + currid;
			window.open(pLocation);
		}

		$('#tt').datagrid('hideColumn', 'ID');
		$('#tt').datagrid('hideColumn', 'ORDER_ID');
		$('#tt').datagrid('hideColumn', 'TENANT_ID');

		function GetDetailTable() {
			$('#tt').edatagrid({
				height: 310,
				toolbar: _detailToolbarData,
				collapsible: 'true', //是否折叠：是
				singleSelect: 'true', //是否单选：是
				rownumbers: 'true',
				fitColumns: 'true', //自动调整列：是
				showFooter: 'true',
				autoSave: 'true',
				columns: [
					[{
						field: 'ID',
						title: 'ID',
						width: '0%',
						align: 'center'
					}, {
						field: 'ORDER_ID',
						title: '事件编号',
						width: '0%',
						align: 'center',
						editor: {
							type: 'textbox',
							options: {
								valueField: "ORDER_ID",
								textField: "ORDER_ID",
								editable: false
							}
						}
					}, {
						field: 'TENANT_ID',
						title: '人员类型ID',
						width: '0%',
						align: 'center',
						editor: {
							type: 'textbox',
							options: {
								valueField: "TENANT_ID",
								textField: "TENANT_ID",
								editable: false
							}
						}
					}, {
						field: 'NAME',
						title: '姓名',
						width: '33%',
						align: 'center',
						editor: {
							type: 'textbox',
						}
					}, {
						field: 'TENANT_TYPE',
						title: '人员类型',
						width: '32%',
						align: 'center',
					}, {
						field: 'MEMO',
						title: '备注',
						width: '32%',
						align: 'center',
						editor: {
							type: 'textbox',
							options: {
								valueField: "MEMO",
								textField: "MEMO",
								editable: true
							}
						}
					}]
				],
				onAdd: function(index, row) {
					currRow = row;
				},
				onDblClickRow: function(index, row) {
					currRow = row;
				},
				onEndEdit: function(index, row, changes) {
					var isNewRecord = row.isNewRecord;
					$.ajax({
						type: 'get',
						dataType: 'JSON',
						url: RemoteLinkAddress + '/market/tenant/findbyname.do?NAME=' + row.NAME,
						success: function(result) {
							var _data = "非市场人员";
							var tenentID = "-1";
							if(result[0] != undefined) {
								tenentID = result[0].ID.toString();
								_data = "市场人员";
							}
							$('#tt').edatagrid('updateRow', {
								index: index,
								row: {
									TENANT_ID: tenentID
								}
							});
							$('#tt').edatagrid('updateRow', {
								index: index,
								row: {
									TENANT_TYPE: _data
								}
							});
							$('#tt').edatagrid('refreshRow', index);
							editDataGridRefresh("end", row, updateData, isNewRecord);
						}
					});
				},
				onDestroy: function(index, row) {
					editDataGridRefresh("destory", row, updateData, false);
				}
			});
		}
	</script>

</html>